package com.java2207.group1.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.java2207.group1.bo.BreakfastBo;
import com.java2207.group1.pojo.Breakfast;
import com.java2207.group1.service.BreakfastService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

/**
 * @author AL 2022/7/26  14:41
 */
@Component
@Scope("prototype")//这里是设置成多例模式
public class WebBreakfastListener extends AnalysisEventListener<BreakfastBo> {
    @Autowired
    private BreakfastService breakfastService;


    @Override
    public void invoke(BreakfastBo data, AnalysisContext analysisContext) {
        System.out.println(data);
        Breakfast breakfast = new Breakfast();
        BeanUtils.copyProperties(data,breakfast);
        breakfastService.addBreakfast(breakfast);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
}
